Skip to content

Primitive Types

Why Programming? Why Java?

ENDURING UNDERSTANDING

LEARNING OBJECTIVE

Call System class methods to generate output to the console.

ESSENTIAL KNOWLEDGE

  • System.out.print and System.out. println display information on the computer monitor.

  • System.out.println moves the cursor to a new line after the information has been displayed, while System.out.print does not.

ENDURING UNDERSTANDING

LEARNING OBJECTIVE

Create string literals.

ESSENTIAL KNOWLEDGE

  • A string literal is enclosed in double quotes.

Variables and Data Types

ENDURING UNDERSTANDING

LEARNING OBJECTIVE

Identify the most appropriate data type category for a particular specification.

ESSENTIAL KNOWLEDGE

  • A type is a set of values (a domain) and a set of operations on them.

  • Data types can be categorized as either primitive or reference.

  • The primitive data types used in this course define the set of operations for numbers and Boolean values.

Expressions and Assignment Statements

ENDURING UNDERSTANDING

LEARNING OBJECTIVE

Evaluate arithmetic expressions in a program code.

ESSENTIAL KNOWLEDGE

  • A literal is the source code representation of a fixed value.

  • Arithmetic expressions include expressions of type int and double.

  • The arithmetic operators consist of +, −, *, /, and %.

  • An arithmetic operation that uses two int values will evaluate to an int value.

  • An arithmetic operation that uses a double value will evaluate to a double value.

  • Operators can be used to construct compound expressions.

  • During evaluation, operands are associated with operators according to operator precedence to determine how they are grouped.

  • An attempt to divide an integer by zero will result in an ArithmeticException to occur.

ENDURING UNDERSTANDING

LEARNING OBJECTIVE

Evaluate what is stored in a variable as a result of an expression with an assignment statement.

ESSENTIAL KNOWLEDGE

  • The assignment operator (=) allows a program to initialize or change the value stored in a variable. The value of the expression on the right is stored in the variable on the left.

  • During execution, expressions are evaluated to produce a single value.

  • The value of an expression has a type based on the evaluation of the expression.

Compound Assignment Operators

ENDURING UNDERSTANDING

LEARNING OBJECTIVE

Evaluate what is stored in a variable as a result of an expression with an assignment statement.

ESSENTIAL KNOWLEDGE

  • Compound assignment operators (+=, −=, *=, /=, %=) can be used in place of the assignment operator.

  • The increment operator (++) and decrement operator (−−) are used to add 1 or subtract 1 from the stored value of a variable or an array element. The new value is assigned to the variable or array element.

Casting and Ranges of Variables

ENDURING UNDERSTANDING

LEARNING OBJECTIVE

Evaluate arithmetic expressions that use casting.

ESSENTIAL KNOWLEDGE

  • The casting operators (int) and (double) can be used to create a temporary value converted to a different data type.

  • Casting a double value to an int causes the digits to the right of the decimal point to be truncated.

  • Some programming code causes int values to be automatically cast (widened) to double values.

  • Values of type double can be rounded to the nearest integer by (int)(x + 0.5) or (int)(x – 0.5) for negative numbers.

  • Integer values in Java are represented by values of type int, which are stored using a finite amount (4 bytes) of memory. Therefore, an int value must be in the range from Integer.MINVALUE to Integer.MAX VALUE inclusive.

  • If an expression would evaluate to an int value outside of the allowed range, an integer overflow occurs. This could result in an incorrect value within the allowed range.